/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.uhfsat;

import com.jme3.bullet.control.BetterCharacterControl;
import com.jme3.math.Vector3f;
import com.jme3.scene.Node;

/**
 *
 * @author Dustin
 */
public class UHFCharacterControl extends BetterCharacterControl implements UHFControl {

	private Node characterNode;
	private float speedFactor = 10000f;

	public UHFCharacterControl(Node characterNode, float radius, float height, float mass) {
		super(radius, height, mass);
		this.characterNode = characterNode;
	}

	@Override
	public void moveLeft(float value, float tpf) {
		Vector3f modelLeftDir = characterNode.getWorldRotation().mult(Vector3f.UNIT_X);
		walkDirection.set(0, 0, 0);
		walkDirection.addLocal(modelLeftDir.mult(-speedFactor * value));
		/*
		if (walkDirection.x > 0) {
			walkDirection.x = 0;
			//walkDirection.addLocal(modelLeftDir.negate().mult(speedFactor * value));
		}
		walkDirection.addLocal(modelLeftDir.mult(-speedFactor * tpf));
		*/

		//setWalkDirection(modelLeftDir.negate().mult(speedFactor * tpf));
	}

	@Override
	public void moveRight(float value, float tpf) {
		Vector3f modelLeftDir = characterNode.getWorldRotation().mult(Vector3f.UNIT_X);
		walkDirection.set(0, 0, 0);
		setWalkDirection(modelLeftDir.mult(speedFactor * value));
		/*
		if (walkDirection.x < 0) {
			walkDirection.x = 0;
			//walkDirection.addLocal(modelLeftDir.mult(speedFactor * value));
		}
		walkDirection.addLocal(modelLeftDir.mult(speedFactor * tpf));
		*/
		//setWalkDirection(modelLeftDir.mult(speedFactor * tpf));
	}

	@Override
	public void moveForward(float value, float tpf) {
		Vector3f modelForwardDir = characterNode.getWorldRotation().mult(Vector3f.UNIT_Z);
		walkDirection.set(0, 0, 0);
		walkDirection.addLocal(modelForwardDir.mult(-speedFactor * value));
		/*
		if (walkDirection.z > 0) {
			walkDirection.z = 0;
			//walkDirection.addLocal(modelForwardDir.negate().mult(speedFactor * value));
		}
		walkDirection.addLocal(modelForwardDir.mult(-speedFactor * tpf));
		*/
		//setWalkDirection(modelForwardDir.negate().mult(speedFactor * tpf));
	}

	@Override
	public void moveBackward(float value, float tpf) {
		Vector3f modelForwardDir = characterNode.getWorldRotation().mult(Vector3f.UNIT_Z);
		walkDirection.set(0, 0, 0);
		walkDirection.addLocal(modelForwardDir.mult(speedFactor * value));
		/*
		if (walkDirection.z < 0) {
			walkDirection.z = 0;
			//walkDirection.addLocal(modelForwardDir.mult(speedFactor * value));
		}
		walkDirection.addLocal(modelForwardDir.mult(speedFactor * tpf));
		*/
		//setWalkDirection(modelForwardDir.mult(speedFactor * tpf));
	}

	@Override
	public void moveLeft(boolean isPressed, float tpf) {
		if (isPressed) {
		}
	}

	@Override
	public void moveRight(boolean isPressed, float tpf) {
		if (isPressed) {
		}
	}

	@Override
	public void moveForward(boolean isPressed, float tpf) {
		if (isPressed) {
		}
	}

	@Override
	public void moveBackward(boolean isPressed, float tpf) {
		if (isPressed) {
		}
	}

	@Override
	public void start(boolean isPressed, float tpf) {
		if (isPressed) {
		}
	}

	@Override
	public void select(boolean isPressed, float tpf) {
		if (isPressed) {
		}
	}

	@Override
	public void lookLeft(float value, float tpf) {
		throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
	}

	@Override
	public void lookRight(float value, float tpf) {
		throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
	}

	@Override
	public void lookUp(float value, float tpf) {
		throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
	}

	@Override
	public void lookDown(float value, float tpf) {
		throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
	}

	@Override
	public void lookLeft(boolean isPressed, float tpf) {
		throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
	}

	@Override
	public void lookRight(boolean isPressed, float tpf) {
		throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
	}

	@Override
	public void lookUp(boolean isPressed, float tpf) {
		throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
	}

	@Override
	public void lookDown(boolean isPressed, float tpf) {
		throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
	}

	@Override
	public void a(boolean isPressed, float tpf) {
		if (isPressed) {
			jump();
		}
	}

	@Override
	public void b(boolean isPressed, float tpf) {
		setDucked(isPressed);
	}

	@Override
	public void x(boolean isPressed, float tpf) {
		Vector3f modelLeftDir = characterNode.getWorldRotation().mult(Vector3f.UNIT_X);
		if (isPressed) {
			walkDirection.addLocal(modelLeftDir.mult(3));
		}
	}

	@Override
	public void y(boolean isPressed, float tpf) {
		if (isPressed) {
		}
	}

	@Override
	public void leftBumper(boolean isPressed, float tpf) {
		throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
	}

	@Override
	public void leftTrigger(float value, float tpf) {
		throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
	}

	@Override
	public void leftTrigger(boolean isPressed, float tpf) {
		throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
	}

	@Override
	public void rightBumper(boolean isPressed, float tpf) {
		throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
	}

	@Override
	public void rightTrigger(float value, float tpf) {
		throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
	}

	@Override
	public void rightTrigger(boolean isPressed, float tpf) {
		throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
	}

}
